package com.lanju.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanju.dao.HouseHoldDao;
import com.lanju.dao.SystemAdminDao;
import com.lanju.dao.UserDao;
import com.lanju.entity.Community;
import com.lanju.entity.House;
import com.lanju.entity.HouseHold;
import com.lanju.entity.SystemAdmin;
import com.lanju.entity.User;
import com.lanju.service.HouseHoldService;

@Service
public class HouseHoldServiceImpl implements HouseHoldService{
	
	@Autowired
	HouseHoldDao houseHoldDao;
	@Autowired
	SystemAdminDao systemAdminDao;
	@Autowired
	UserDao userDao;
	
   

	@Override
	public Map<String, Object> getHouseHold(Integer id) {
		 Map<String, Object> result=new HashMap<String, Object>();
		try {
			SystemAdmin systemAdmin=houseHoldDao.getSystemAdmin(id);
			HouseHold houseHold=systemAdmin.getHousrHold();
			result.put("systemAdmin", systemAdmin);
			result.put("detail", houseHold);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@SuppressWarnings("unused")
	@Override
	public Map<String, Object> getHouseHoldList() {
		Map<String, Object> map=new HashMap<>();
		 List<HouseHold>  l=houseHoldDao.getHouseHoldList();
		try {
			map.put("rows", houseHoldDao.getHouseHoldList());
		} catch (Exception e) {
			map.put("rows", null);
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public Map<String, Object> getAllUser(Map<String, Object> map) {
		 Map<String, Object> result=null;
		try {
			result = new HashMap<>();
			List<Community> communitylist=userDao.getAreaCommunityList(map);
			String community_id="";
			if(communitylist !=null && communitylist.size()>0){
				for(int i=0;i<communitylist.size();i++){
					community_id+="'"+communitylist.get(i)+"',";
				}
				map.put("community_id", community_id.substring(0, community_id.length()-1));
			}
			List<House> houseList = userDao.getAllHouseList(map);
			String userId="";
			if(houseList != null && houseList.size()>0){
				for(int i=0;i<houseList.size();i++){
					House h=houseList.get(i);
					userId+="'"+h.getUser().getUserId()+"',";
				}
				map.put("userId", userId.substring(0, userId.length()-1));
			}
			List<User> list=userDao.getAllUser(map);
			result.put("rows", list);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return result;
	}

}
